﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Index.Master" Inherits="System.Web.Mvc.ViewPage<DAL.SysRole>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
     $(function () {
         //按钮操作函数
         flexiSelect = function (ids, grid) {
             //主键列和显示列之间用 ^ 分割   每一项用 , 分割
             var arr = new Array(0);
             $('.trSelected  td:nth-child(1) div', grid.gDiv).each(function () {
                 //遍历选中行对象，获取值第一列（Id）
                 arr.push($(this).text());
             })
             $('.trSelected  td:nth-child(3) div', grid.gDiv).each(function (i) {
                 //遍历选中行对象，获取值第三列（ Name）
                 if (i == 0) {
                     arr.push("^"); //主键列和显示列的分割符 ^ 
                     i++;
                 }
                 arr.push($(this).text()); //将值插入数组
             })
             if (arr.length < 3) {//少于一条
                 msgShow("操作提示", "请选择数据!", "info");
                 return;
             }
             //                if (arr.length > 3) {//多于一条
             //                    alert("请只选择一条数据!");
             //                    return;
             //                }
             if (arr.length >= 3) {//一条数据和多于一条
                 returnParent(arr.join("&")); //每一项用 & 分割
             }
         }
         flexiQuery = function (ids, grid) {
             $('#divQuery').window({
                 collapsible: false,
                 minimizable: false,
                 maximizable: false,
                 tools: [{
                     iconCls: 'icon-search',
                     handler: function () {
                         var search = "";
                         $('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
                             search = search + this.id + "&" + this.value + "^";
                         });
                         grid.doSearch(search); //执行查询
                         $("#flexigridDataSef").flexReload(); //刷新
                         $('#divQuery').window('close');
                     }
                 }]
             });
             $('#divQuery').window('open');
         };

         flexiOut = function (ids, grid) {
             var queryJDiv = $(".divQuery:last"); //选择div中的数据

             var search = "";
             queryJDiv.find(":text,:selected,textarea,:hidden,:checked,:password").each(function () {
                 search = search + this.id + "&" + this.value + "^";

             });

             grid.doDaoChu("../SysRole/GetDaoChu");
         };
         flexiView = function (ids, grid) {
             var arr = new Array(0);
             $('.trSelected  td:nth-child(1) div', grid.gDiv).each(function (i) {
                 //遍历选中行对象，获取值第一列（id）
                 arr.push($(this).text());
             })
             if (arr.length == 0) {
                 msgShow("操作提示", "请选择数据!", "info");
                 return;
             }
             if (arr.length > 1) {
                 msgShow("操作提示", "请只选择一条需要查看的数据!", "info");
                 return;
             }
             if (arr.length == 1) {
                 var parent = window.dialogArguments; //获取父页面
                 if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                     msgShow("操作提示", "请不要在弹出框中新建，可以转到列表中查看！", "info");
                     return;
                 }
                 window.location.href = "../SysRole/Details/" + arr[0];
                 return;
             }
         }
         function flexiCreate() {
             var parent = window.dialogArguments; //获取父页面
             if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                 msgShow("操作提示", "请不要在弹出框中新建，可以转到列表中新建！", "info");
                 return;
             }
             window.location.href = "../SysRole/Create/" + $("#hidtreeid").val();
             return;
         }
         flexiModify = function (ids, grid) {
             var parent = window.dialogArguments; //获取父页面
             if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                 msgShow("操作提示", "请不要在弹出框中修改，可以转到列表中修改！", "info");
                 return;
             }
             var arr = new Array(0);
             $('.trSelected  td:nth-child(1) div', grid.gDiv).each(function (i) {
                 //遍历选中行对象，获取值第一列（id）
                 arr.push($(this).text());
             })
             if (arr.length == 0) {
                 msgShow("操作提示", "请选择数据!", "info");
                 return;
             }
             if (arr.length > 1) {
                 msgShow("操作提示", "请只选择一条需要查看的数据!", "info");
                 return;
             }
             if (arr.length == 1) {
                 window.location.href = "../SysRole/Edit/" + arr[0];
                 return;
             }
         };

         flexiDelete = function (ids, grid) {
             var parent = window.dialogArguments; //获取父页面
             if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                 msgShow("请不要在弹出框中删除，可以转到列表中删除！", "info");
                 return;
             }
             var arr = new Array(0);
             $('.trSelected  td:nth-child(1) div', grid.gDiv).each(function (i) {
                 //主要的一列，遍历选中行对象，获取值第一列（id）
                 arr.push($(this).text());
             })
             if (arr.length == 0) {
                 msgShow("操作提示", "请选择数据!", "info");
                 return;
             }
             $.messager.confirm('删除提示', '确认删除这' + arr.length + '项吗?', function (r) {
                 if (r) {
                     $.post("../SysRole/Delete", { query: arr.join(",") }, function (res) {
                         if (res == "OK") {
                             $("#flexigridDataSef").flexReload();
                             msgShow("操作提示", "删除成功!", "info");
                         }
                         else {
                             if (res == "") {
                                 msgShow("操作提示", "删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。", "info");

                             }
                             else {
                                 msgShow("操作提示", res, "info");

                             }
                         }
                     });
                 }
                 else
                     return;
             });
         };


         $("#flexigridDataSef").flexigrid(
			{
			         url: '../SysRole/FlexigridList',
			    colModel: [
				   { display: '<%: Html.LabelFor(model => model.Id) %>', name: 'Id', width: 205, hide: true, sortable: false, align: 'left' }
					, { display: '序号', name: 'MySeq', width: 26, sortable: false, align: 'left' }
					, { display: '<%: Html.LabelFor(model => model.Name) %>', name: 'Name', width: 83, sortable: true, align: 'left' }
					, { display: '<%: Html.LabelFor(model => model.Description) %>', name: 'Description', width: 83, sortable: true, align: 'left' }
					, { display: '<%: Html.LabelFor(model => model.State) %>', name: 'State', width: 83, sortable: true, align: 'left' }
					//, { display: '<%: Html.LabelFor(model => model.SysPerson) %>', name: 'SysPersonId', width: 83, sortable: false, align: 'left' }
					//, { display: '<%: Html.LabelFor(model => model.SysPromise) %>', name: 'SysPromiseId', width: 83, sortable: false, align: 'left' }
					//, { display: '<%: Html.LabelFor(model => model.SysMenu) %>', name: 'SysMenuId', width: 83, sortable: false, align: 'left' }

                   	],
			    buttons: [
                    { name: '查询', bclass: 'searchcss', onpress: flexiQuery },
                    { separator: true },
                    { name: '详细', bclass: 'detailcss', onpress: flexiView },
                    { separator: true },
                    { name: '创建', bclass: 'addcss', onpress: flexiCreate },
                    { separator: true },
				    { name: '删除', bclass: 'deletecss', onpress: flexiDelete },
                    { separator: true },
                    { name: '修改', bclass: 'editcss', onpress: flexiModify },
				    { separator: true },
                    { name: '选择', bclass: 'selectcss', onpress: flexiSelect }
			    //				    ,{ separator: true },
			    //                    { name: '导出', bclass: 'excelcss', onpress: flexiOut }

				],
			    sortname: "CreateTime",
			    sortorder: "asc",
			    usepager: true,
			    useRp: true,
			    showTableToggleBtn: true,
			    height: 300

			});
         var parent = window.dialogArguments; //获取父页面
         if (parent == "undefined" || parent == null) {
             $(".fbutton:last").hide();
         } else {
             $(".fbutton").hide();
             $(".fbutton:first").show();
             $(".fbutton:last").show();
         }
         using('tree', function () {
             $('#myTree').tree({

                 url: '../SysDepartmentTree/GetTree',
                 onClick: function (node) {
                     if (node != null && node.id != null && node.id != "undefined") {
                         if (node.iconCls != null) {//&& node.iconCls == 'icon-ok'
                             $("#hidtreeid").val('');
                             $("#flexigridDataSef").flexReload(''); //根目录刷新  
                         } else {
                             $("#hidtreeid").val(node.id);
                             $("#flexigridDataSef").flexReload(node.id); //子节点刷新
                         }

                     }
                 }
             });
         });
     });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="easyui-layout" style="width: 98%; height: 480px;">
        <div region="west" split="true" title="模块列表" style="width: 260px;">
            <ul id="myTree">
            </ul>
        </div>
        <div id="content" region="center" title="角色列表" style="padding: 5px;">
            <table id="flexigridDataSef">
            </table>
        </div>
        <div id="divQuery" title="查询列表" class="easyui-window" closed="true" modal="false"
            style="padding: 5px; background: #fafafa;">
            <div class="input">
                <div class="editor-label">
                    <%: Html.LabelFor(model => model.Name) %>
                </div>
                <div class="editor-field">
                    <%: Html.EditorFor(model => model.Name) %>
                </div>
            </div>
            <br style="clear: both;" />
            <div class="input">
                <div class="editor-label">
                    <%: Html.LabelFor(model => model.State) %>
                </div>
                <div class="editor-field">
                    <%=Html.DropDownListFor(model => model.State,App.Models.SysFieldsDDL.GetSysFields("SysRole","State"),"请选择")%>
                </div>
            </div>
            <br style="clear: both;" />
        </div>
        <input id="hidtreeid" type="hidden" />
        <div id="dialo" title="操作">
        </div>
    </div>
</asp:Content>
